#!/bin/bash

# API测试脚本
BASE_URL="http://localhost:8080"

echo "=== Spring Boot 用户登录系统 API 测试 ==="
echo ""

# 测试服务是否启动
echo "1. 测试服务状态..."
curl -s "$BASE_URL/api/user/test"
echo ""
echo ""

# 测试登录功能
echo "2. 测试用户登录..."
echo "登录 admin 用户:"
curl -s -X POST "$BASE_URL/api/user/login" \
  -H "Content-Type: application/json" \
  -d '{"username":"admin","password":"admin123"}' | jq .
echo ""
echo ""

echo "登录 user1 用户:"
curl -s -X POST "$BASE_URL/api/user/login" \
  -H "Content-Type: application/json" \
  -d '{"username":"user1","password":"user123"}' | jq .
echo ""
echo ""

# 测试错误登录
echo "3. 测试错误登录..."
echo "用户名错误:"
curl -s -X POST "$BASE_URL/api/user/login" \
  -H "Content-Type: application/json" \
  -d '{"username":"wronguser","password":"admin123"}' | jq .
echo ""
echo ""

echo "密码错误:"
curl -s -X POST "$BASE_URL/api/user/login" \
  -H "Content-Type: application/json" \
  -d '{"username":"admin","password":"wrongpass"}' | jq .
echo ""
echo ""

# 测试注册功能
echo "4. 测试用户注册..."
echo "注册新用户:"
curl -s -X POST "$BASE_URL/api/user/register" \
  -H "Content-Type: application/json" \
  -d '{"username":"testuser","password":"test123","email":"test@example.com","name":"测试用户","age":25}' | jq .
echo ""
echo ""

echo "=== 测试完成 ==="
echo "访问 http://localhost:8080/login.html 查看Web登录页面" 